package com.dayaokeji.rhythmschoolstudent.boxing.impl;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;

import com.bilibili.boxing.loader.IBoxingCrop;
import com.bilibili.boxing.model.config.BoxingCropOption;
import com.soundcloud.android.crop.Crop;

/**
 * Created by Gorden on 2017/11/7.
 */

public class BoxingCropImpl implements IBoxingCrop {

    @Override
    public void onStartCrop(Context context, Fragment fragment, @NonNull BoxingCropOption boxingCropOption, @NonNull String path, int requestCode) {
        Uri uri = new Uri.Builder()
                .scheme("file")
                .appendPath(path)
                .build();
        Crop.of(uri, boxingCropOption.getDestination()).asSquare().start(context,fragment,requestCode);
    }

    @Override
    public Uri onCropFinish(int i, Intent data) {
        if (data == null) {
            return null;
        }
        Throwable throwable = Crop.getError(data);
        if (throwable != null) {
            return null;
        }
        return Crop.getOutput(data);
    }
}
